// JavaScript Document
(function(window){
	function Progress($progress,$progressIn,$progressTar){
		return new Progress.prototype.init($progress,$progressIn,$progressTar);
		
		}
	Progress.prototype={
		constroustor:Progress,
		init:function($progress,$progressIn,$progressTar){
			//保存传进来的数据
			this.$progress=$progress;
			this.$progressIn = $progressIn;
			this.$progressTar = $progressTar;
			
			},
			 /* isMove:false,*/
			  
			progressClick:function(callBack){
				
				var $this=this;
				//监听点击事件
				this.$progress.click(function(event){
					$this.isMove=true;
				var normalLeft = $(this).offset().left;
				var eventLeft = event.pageX;
				var nowLeft = eventLeft-normalLeft;
				//tar点
				$this.$progressTar.css("left",nowLeft);
				//前景色条
				$this.$progressIn.css("width",nowLeft);
				var value = nowLeft/$this.$progress.width();
				callBack(value);
				
				
				});
				},
			progressMove:function(callBack){
					var $this=this;
				   //监听鼠标移动事件
					var nowLeft; 
					 var progressWidth=$this.$progress.width();
				this.$progress.mousedown(function(){
					
					 $this.isMove = true;
					
					//鼠标按下状态
					$(document).mousemove(function(event){
					 var normalLeft = $this.$progress.offset().left;
						var eventLeft = event.pageX;
						nowLeft = eventLeft-normalLeft;
						
						
					console.log(nowLeft)
					if(nowLeft<=0){
						nowLeft=0;
						
						}
					if(nowLeft>=progressWidth){
						nowLeft=progressWidth;
						
						}
						//tar点
						$this.$progressTar.css("left",nowLeft);
						//前景色条
						$this.$progressIn.css("width",nowLeft);
						
						
						});
					$(document).mouseup(function(){
						$(document).off("mousemove")
					
						//计算进度条比例
				        var value = nowLeft/$this.$progress.width();
				        callBack(value)
					    $this.isMove = false;
						})
					
					
					});
				
				},
				//进度条同步
				progressSynchro:function(value){
			 		if(this.isMove) return;
			           //tar点
						this.$progressTar.css({
							left: value+"%"});
						//前景色条
						this.$progressIn.css({
							width:value+"%"});
						if(value ==100){
							//歌曲放完，自动播放下一首
							$(".play_next").trigger("click");
							
							}
					},

		}
	Progress.prototype.init.prototype=Progress.prototype;
	window.Progress = Progress;
	
	
	}(window))